42 Vowel Count 7 kyu


Posted by mijouhsieh on 2024-01-04

7 kyu Vowel Count

題目說明:

函式帶入字串判斷有幾個母音(a,e,i,o,u)

code
export class Kata {
  static getCount(str: string): number {
    //code
    const lowerCaseStr = str.trim().toLowerCase();
    const regex = /[aeiou]/g;
    const matches = lowerCaseStr.match(regex);

    if (matches) {
      return matches.length;
    } else {
      return 0;
    }
  }
}

#TypeScript #string.match() #RegEx







Related Posts

React-[useEffect篇]- 元件的生命週期 與 useEffect hook ,與錯誤處理

React-[useEffect篇]- 元件的生命週期 與 useEffect hook ,與錯誤處理

網路協定 HTTP?DNS?

網路協定 HTTP?DNS?

[演講筆記] 突破學習困境與職涯瓶頸的行動指南 - 學習長阿康 : 我的人生策略與學習方法論

[演講筆記] 突破學習困境與職涯瓶頸的行動指南 - 學習長阿康 : 我的人生策略與學習方法論


Comments